package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Planreceivable;
import cn.gson.springboot.model.service.PlanReceivableService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class PlanReceivableController {
    @Autowired
    PlanReceivableService planReceivableService;
    @Autowired
    HttpSession session;
    @RequestMapping("/planreceivable-list")
    @ResponseBody
    public Map<String,Object> PlanReceivableList(Integer page,Integer size,Integer filter,Integer vague,String content){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Planreceivable> planreceivables = planReceivableService.selectPlanReceivable(emp.getDepartment().getDeptId(),emp.getEmpId(),filter,vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",planreceivables);
        return map;
    }
    //按id查询
    @RequestMapping("/planreceivable-back-plan")
    @ResponseBody
    public Planreceivable planReceivableList(Integer backId){
        Planreceivable pay = planReceivableService.selectPlanReceivableById(backId);
        return pay;
    }

    @RequestMapping("/pay-back-con-list")
    @ResponseBody
    public List<Planreceivable> payBackConList(Integer conId){
        List<Planreceivable> plan = planReceivableService.selectBackByConId(conId);
        return plan;
    }

    @RequestMapping("/contract-plan-past-future-thirty-list")
    @ResponseBody
    public List<Planreceivable> selectContractPlanPastFutureThirty(){
        List<Planreceivable> plan = planReceivableService.selectContractPlanPastFutureThirty();
        return plan;
    }

    @RequestMapping("/contract-plan-month-list")
    @ResponseBody
    public List<Planreceivable> selectContractPlanMonth(){
        List<Planreceivable> plan = planReceivableService.selectContractPlanMonth();
        return plan;
    }
    //新增修改回款计划
    @RequestMapping("/save-planreceivable")
    @ResponseBody
    public void savePlanreceivable(@RequestBody Planreceivable planreceivable){
        System.out.println(planreceivable);
        planReceivableService.savePlanreceivable(planreceivable);
    }

    //删除回款计划
    @RequestMapping("/delete-planreceivable")
    @ResponseBody
    public void deletePlanreceivable(@RequestParam(value = "planreceivableId") Integer planreceivableId){
        planReceivableService.deletePlanreceivable(planreceivableId);
    }
}
